#/bin/bash!
yum install openstack-neutron-ml2  -y 
mv /etc/neutron/plugins/ml2/ml2_conf.ini /etc/neutron/plugins/ml2/ml2_conf.ini.save.`date +%s`

cat > /etc/neutron/plugins/ml2/ml2_conf.ini << EOF
[ml2]
type_drivers = gre
tenant_network_types = gre
mechanism_drivers = openvswitch

[ml2_type_flat]

[ml2_type_vlan]

[ml2_type_gre]
tunnel_id_ranges = 1:100

[securitygroup]
firewall_driver = neutron.agent.linux.iptables_firewall.OVSHybridIptablesFirewallDriver
enable_security_group = True

[ovs]
local_ip = `hostname -i`
tunnel_type = gre
enable_tunneling = True
EOF
ln -s /etc/neutron/plugins/ml2/ml2_conf.ini /etc/neutron/plugin.ini

sed -i 's,plugins/openvswitch/ovs_neutron_plugin.ini,plugin.ini,g' /etc/init.d/neutron-openvswitch-agent
openstack-config --set /etc/nova/nova.conf DEFAULT  linuxnet_interface_driver nova.network.linux_net.LinuxOVSInterfaceDriver 
openstack-config --set /etc/neutron/neutron.conf DEFAULT service_plugins router
openstack-config --set /etc/neutron/neutron.conf DEFAULT core_plugin ml2

service openstack-nova-compute restart 
service neutron-openvswitch-agent restart

if [ "$1" == "neutron" ]; then
	INTERFACE_NAME=eth0
	ovs-vsctl add-port br-ex $INTERFACE_NAME
	ethtool -K $INTERFACE_NAME gro off
	cp  /etc/sysconfig/network-scripts/ifcfg-eth0  /etc/sysconfig/network-scripts/ifcfg-br-ex
	sed s/DEVICE=eth0/DEVICE=br-ex/ -i /etc/sysconfig/network-scripts/ifcfg-br-ex
	sed -e 's/IPADDR=.*//' -e  's/NETMASK=.*//' -e 's/GATEWAY=.*//' -i  /etc/sysconfig/network-scripts/ifcfg-eth0
	service network restart
fi

